import axios from "axios";
// import { useRouter } from "vue-router";
import { useUserStore } from "@/stores";
const userStore = useUserStore();
// const router = useRouter();

const baseURL = import.meta.env.VITE_BASE_URL + '/api/';

const ins = axios.create({
    baseURL,
    // timeout: 5000,
});


// 设置 请求拦截
ins.interceptors.request.use((config) => {
    config.headers.language = userStore.getLocale;


    let token = userStore.getToken;
    if (token) {
        config.headers.Authorization = token
    }
    // 手动归集时, timeout 设置为 50s，防止请求超时
    if (config.url === '/v2/manualCollection') {
        config.timeout = 0
    }
    return config;
}, (err) => {
    return Promise.reject(err);
});

// 设置响应拦截
ins.interceptors.response.use((res) => {
    // console.log('响应拦截');
    res = res.data;
    return res;
}, (err) => {
    return Promise.reject(err);
})

export default ins;
